/* 1、头像、昵称、ID、会员状态、颜值币
 * */
var shenhe = true;
if(!isallpay()) {
	shenhe = false;
	mui('.my-vipimg')[0].style.display = "none";
	mui('.mycoin')[0].style.display = "none";
	document.getElementById("member").style.display = "none";
};
var My = new Vue({
	el: '.mui-content',
	data: {
		items: user_info,
		fans: 0
	},
	filters: {
		getvip: function() {
			if(isvipcoin(false)) {
				return '../img/wallet/mb.png';
			} else {
				return '../img/my/huiyuan.png';
			}
		},
		Timeconversion: function(shijianchuo) {
			var timestamp = (Date.parse(new Date())) / 1000;
			if(shijianchuo > timestamp) {
				var date = new Date(vip * 1000);
				var y = date.getFullYear();
				var m = date.getMonth() + 1;
				var d = date.getDate();
				var t = y + '年' + m + '月' + d + '日 到期 ';
				return t;
			} else {
				return '未开通';
			}
		},
		headimg: function(value) {
			if(value) {
				return value;
			} else {
				return '../img/function/mtoux.jpg';
			}

		}
	}
});
var fd = plus.storage.getItem('My_fans');
if(fd) {
	My.fans = JSON.parse(fd).length;
}
//打开页面
mui(".list").on("tap", "a", function() {
	var targetTab = this.getAttribute('data-url');
	if(targetTab == 'my/Myfans.html') {
		if(My.fans == 0) {
			mui.toast('暂时还没有人关注你');
			return;
		}
		if(shenhe && !isvipcoin(false)) {
			showTanChuang('想知道哪些美女关注了你吗？','我想知道','我不好奇',2,'page/wallet.html')
			return;
		}
	}
	var type = 1;
	if(targetTab == 'page/wallet.html') {
		if(this.getAttribute('id') == 'huiyuan') {
			type = 2;
		}
		openWallet('page/wallet.html',type)
		return;
	}
	mui.openWindow({
		url: targetTab,
		id: targetTab,
		extras: {
			type: type
		}
	})
});
mui(".my-center").on("tap", ".my-vipimg", function() {
	openWallet('page/wallet.html',2)
});
function clickButton(){
	alert(1)
}
mui('.my-center-bottom').on('tap', '.chongzhi', function() {
	openWallet('page/wallet.html',1)
})

//资料处理
var selfoff = true;
var self = plus.webview.currentWebview();
mui('.my-right')[0].addEventListener('tap', function() {
	mui.openWindow({
		url: 'my/Data.html',
		id: 'Data',
		styles: { // 窗口参数 参考5+规范中的WebviewStyle,也就是说WebviewStyle下的参数都可以在此设置
			titleNView: { // 窗口的标题栏控件
				autoBackButton: true,
				titleText: "我的资料", // 标题栏文字,当不设置此属性时，默认加载当前页面的标题，并自动更新页面的标题
				titleColor: "#FFFFFF", // 字体颜色,颜色值格式为"#RRGGBB",默认值为"#000000"
				titleSize: "18px", // 字体大小,默认17px
				backgroundColor: "#fd698d", // 控件背景颜色,颜色值格式为"#RRGGBB",默认值为"#F7F7F7"
				splitLine: { // 标题栏控件的底部分割线，类似borderBottom
					color: "#CCCCCC", // 分割线颜色,默认值为"#CCCCCC"  
					height: "1px" // 分割线高度,默认值为"2px"
				}
			}
		}
	});
	//	if(selfoff) {
	//		this.children[0].setAttribute('src', '../img/my/fanhui.png');
	//		var hheinht = mui('.my-top')[0].offsetHeight;
	//		var baiduWV = plus.webview.create('my/Data.html', "Data", {
	//			top: hheinht + 'px',
	//			bottom: 0
	//		});
	//		self.append(baiduWV);
	//		selfoff = false;
	//	} else {
	//		var ziweb = plus.webview.getWebviewById('Data');
	//		plus.webview.close(ziweb, 'fade-out');
	//		this.children[0].setAttribute('src', '../img/my/ziliao.png');
	//		selfoff = true;
	//	}

})

//头像处理
mui(".left").on("tap", 'img', function() {
	var a = [{
		title: "拍照"
	}, {
		title: "从相册选择"
	}];
	plus.nativeUI.actionSheet({
		title: "修改头像",
		cancel: "取消",
		buttons: a
	}, function(b) {
		switch(b.index) {
			case 0:
				break;
			case 1:
				upImg.getImage();
				break;
			case 2:
				upImg.galleryImg();
				break;
			default:
				break
		}
	})
	//	}

});
var upImg = {
	getImage: function() {
		var c = plus.camera.getCamera();
		c.captureImage(function(e) {
			plus.io.resolveLocalFileSystemURL(e, function(entry) {
				cutImage(entry.toLocalURL());
			}, function(e) {})
		}, function(s) {}, {
			filename: "_doc/head.jpg"
		})
	},
	galleryImg: function() {
		plus.gallery.pick(function(a) {
			plus.io.resolveLocalFileSystemURL(a, function(entry) {
				cutImage(entry.toLocalURL())
			}, function(e) {})
		}, function(a) {}, {
			filter: "image"
		})
	}
}

function cutImage(path) {
	mui.openWindow({
		url: '../html/my/headimg.html',
		id: 'My-headimg',
		extras: {
			path: path,
			type: 0
		},
		show: {
			aniShow: 'zoom-fade-in',
			duration: 200
		}
	})
}
window.addEventListener('GZfans', function() {
	My.fans += 1;
})
window.addEventListener('myupdate', function(event) {
	user_info = JSON.parse(plus.storage.getItem("user_info"));
	My.items = user_info;
})
window.addEventListener('updateHeadImg', function(event) {
	var imgurl = event.detail.img_path;
	showWaiting('正在上传', '../');
	var url = getApiUrl('http://www.jiaoyou0.cn', 'index/uploadB64');
	mui.ajax({
		type: "post",
		url: url,
		async: true,
		dataType: 'json',
		data: {
			'fl': 0,
			'image': imgurl
		},
		success: function(data) {
			plus.nativeUI.closeWaiting();
			if(data.code == 200) {
				user_info.headimg = data.data;
				plus.storage.setItem('user_info', JSON.stringify(user_info));
				var WebId_MsgChat = plus.webview.getWebviewById('Msg_Chat');
				mui.fire(WebId_MsgChat, 'getheadimg');
			}
		},
		error: function(xhr, type, errorThrown) {
			plus.nativeUI.closeWaiting()
			mui.toast('上传失败，请重试')
		}
	});
});

//上传头像结束
var backButtonPress = 0;
mui.back = function(event) {
	backButtonPress += 1;
	if(backButtonPress > 1) {
		plus.runtime.quit()
	} else {
		plus.nativeUI.toast('再按一次退出应用')
	};
	setTimeout(function() {
		backButtonPress = 0
	}, 1000);
	return false
};